<template>

  <el-scrollbar height="812px">
    <div class="goodeName multi-line-omit">{{ props.goodData.subjectTrans }}</div>
    <div class="tishi">
      <span class="hiu">Входите в зону и проверьте еще один товар.</span>
      <span class="hong">Нажмите для просмотра>></span>
    </div>
    <div class="tip">
      <el-tag type="warning" style="margin-right: 8px;margin-bottom: 6px" v-for="(item,index) of state.tagList" :key="index">{{ item }}</el-tag>
    </div>
    <div class="kucun">
      Продано：{{ props.goodData.soldOut }}
    </div>
    <div class="goodeTypeList">
      <div class="item" :class="index === 0 ? 'item_action':'item'" v-for="(item,index) of state.wholesaleList">
        <div class="typeText">{{ item.startQuantityStr }} pairs</div>
        <div class="typeMoney">RUB {{ item.priceRuble }}</div>
      </div>
    </div>
    <div class="typeSelect">
      <div class="title">
        <div>{{ state.firstSpecificationName }}：<span style="color: #F83C57">（{{ state.typeSelectItemName }}）</span>
        </div>
      </div>
      <div class="typeSelectList">
        <div class="typeSelectItem" v-for="(item,index) of state.goodTypeData.list" :key="index"
             :class="index === state.typeSelectItemIndex ? 'typeSelectItem_action':'typeSelectItem'"
             @click="selectAProductFun(item,index)"
        >
          <img :src="item.skuImageUrl" alt="">
        </div>
      </div>
    </div>
    <div class="typeSelect" v-if="state.goodTypeData.haveChild === 1">
      <div class="title">
        <div>{{ state.typeSelectItemChild[0].attributeNameTrans }}：<span style="color: #F83C57"></span></div>
      </div>
      <div class="typeSelectList">
        <div :class="index === state.childIndex ? 'typeSelectTextItem_action':'typeSelectTextItem'"
             v-for="(item,index) of state.typeSelectItemChild" :key="index" @click="typeSelectItemChildFun(index,iten)">
          {{ item.valueTrans }}
        </div>
      </div>
    </div>
    <div class="typeSelect" style="border: none">
      <div class="title">Логистика</div>
      <div class="noDataText">Выбранное количество Нет транспортных решений</div>
    </div>
    <div class="btnList">
      <div class="buyBtn shiyongBtn" @click="initiateOrderFun('1')">Купить сразу</div>
      <div class="shopping shiyongBtn" @click="initiateOrderFun('2')">Заказать</div>
      <div class="collect iconBtn">
        <img src="../../assets/image/xqsc.png" alt="">
      </div>
      <div class="share iconBtn">
        <img src="../../assets/image/fx.png" alt="">
      </div>
    </div>
  </el-scrollbar>

</template>
<script setup lang="ts">
import {reactive, defineProps, watch, defineEmits} from 'vue'
import {getGoodsSkuAttribute} from "@/api/api.ts";

const emits = defineEmits(['regressionImg','initiateOrder'])
const props = defineProps({
  goodData: {
    type: Object,
    default() {
      return {}
    }
  }
})
const state = reactive({
  goodTypeData: {},
  typeSelectItemIndex: 0,
  typeSelectItemObj: {},
  typeSelectItemName: '',
  typeSelectItemChild: [],
  wholesaleList: [],
  childIndex: 0,
  firstSpecificationName:'',
  tagList: []
})
const addQuantityRangeField = (data: any) => {
  return data.map((item: any, index: any, array: any) => {
    const nextItem = array[index + 1];
    const start = item.startQuantity;
    const end = nextItem ? nextItem.startQuantity - 1 : '↑';
    item.startQuantityStr = `${start}-${end}`;
    return item;
  });
};
watch(() => props.goodData, () => {


  state.goodTypeData = props.goodData.attributeSkuInfos
  state.tagList = props.goodData.serverTransList
  state.firstSpecificationName = state.goodTypeData.list[0].attributeNameTrans
  state.typeSelectItemObj = props.goodData.attributeSkuInfos.list[0]
  state.typeSelectItemName = props.goodData.attributeSkuInfos.list[0].valueTrans
  if (state.goodTypeData.haveChild === 1) state.typeSelectItemChild = props.goodData.attributeSkuInfos.list[0].child

  state.wholesaleList = addQuantityRangeField(props.goodData.productSaleInfo.priceRangeList)
})
//暂时禁用
const getGoodsSkuAttributeFun = (topId: any) => {
  getGoodsSkuAttribute({offerId: topId}).then(res => {
    console.log(res)
    if (res.errCode === 0) {
      // state.goodTypeData = res.returnData
      // state.typeSelectItemObj = res.returnData.list[0]
      // state.typeSelectItemName = res.returnData.list[0].valueTrans
      // if (state.goodTypeData.haveChild === 1) state.typeSelectItemChild = res.returnData.list[0].child
    }
  })
}
const selectAProductFun = (item: object, index: number) => {
  state.childIndex = 0
  state.typeSelectItemIndex = index
  state.typeSelectItemName = item.valueTrans
  state.typeSelectItemObj = item
  if (state.goodTypeData.haveChild === 1) state.typeSelectItemChild = item.child
  emits('regressionImg', item.skuImageUrl)
}
const typeSelectItemChildFun = (index,item) => {
  state.childIndex = index
}

const initiateOrderFun = (index:any) => {
  emits('initiateOrder', index)
}

</script>
<style scoped lang="less">
.zujian {
  height: 812px;
  overflow: auto;
}

.multi-line-omit {
  word-break: break-all; // 允许单词内自动换行，如果一个单词很长的话
  text-overflow: ellipsis; // 溢出用省略号显示
  overflow: hidden; // 超出的文本隐藏
  display: -webkit-box; // 作为弹性伸缩盒子模型显示
  -webkit-line-clamp: 2; // 显示的行
  -webkit-box-orient: vertical; // 设置伸缩盒子的子元素排列方式--从上到下垂直排列
}

.goodeName {
  font-family: Segoe UI, Segoe UI;
  font-weight: bold;
  font-size: 24px;
  color: #333333;
  line-height: 24px;
  text-align: left;
  font-style: normal;
  text-transform: none;
}

.tishi {
  font-family: Segoe UI, Segoe UI;
  font-weight: 600;
  font-size: 14px;
  color: #999999;
  line-height: 14px;
  text-align: left;
  font-style: normal;
  text-transform: none;
  margin-top: 12px;
}

.hong {
  color: #F83C57;
  cursor: pointer;
}

.tip {
  margin-top: 12px;
}

.kucun {
  font-family: Segoe UI, Segoe UI;
  font-weight: 600;
  font-size: 12px;
  color: #333333;
  line-height: 12px;
  text-align: left;
  font-style: normal;
  text-transform: none;
  margin-top: 12px;
}

.goodeTypeList {
  margin-top: 25px;
  padding-top: 20px;
  //padding-bottom: 20px;
  border-top: 1px solid #EEEEEE;
  border-bottom: 1px solid #EEEEEE;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;

  .item {
    width: 275px;
    height: 72px;
    background: #FFFFFF;
    box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.15);
    border-radius: 8px 8px 8px 8px;
    margin-bottom: 20px;
    color: #333333;
    box-sizing: border-box;
    padding: 10px 36px;
    cursor: pointer;

    .typeText {
      color: #999999;
    }
  }

  .item_action {
    width: 275px;
    height: 72px;
    background: #0070E9;
    box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.15);
    border-radius: 8px 8px 8px 8px;
    color: white;
    cursor: pointer;

    .typeText {
      color: white;
    }
  }

  .typeText {
    font-family: Segoe UI, Segoe UI;
    font-weight: 600;
    font-size: 16px;
    //color: #FFFFFF;
    line-height: 16px;
    text-align: left;
    font-style: normal;
    text-transform: none;
    margin-bottom: 8px;
  }

  .typeMoney {
    //width: 117px;
    height: 24px;
    font-family: Segoe UI, Segoe UI;
    font-weight: bold;
    font-size: 24px;
    //color: #FFFFFF;
    line-height: 24px;
    text-align: left;
    font-style: normal;
    text-transform: none;
  }
}

.typeSelect {
  padding: 20px 0;
  border-bottom: 1px solid #EEEEEE;

  .title {
    font-family: Segoe UI, Segoe UI;
    font-weight: bold;
    font-size: 16px;
    color: #333333;
    line-height: 16px;
    text-align: left;
    font-style: normal;
    text-transform: none;
    display: flex;
    justify-content: space-between;
    cursor: pointer;
  }

  .typeSelectList {
    display: flex;
    flex-wrap: wrap;

    .typeSelectItem {
      width: 64px;
      height: 64px;
      border-radius: 8px 8px 8px 8px;
      margin-right: 16px;
      overflow: hidden;
      margin-top: 20px;
      cursor: pointer;

      img {
        width: 100%;
      }
    }

    .typeSelectItem_action {
      box-sizing: border-box;
      border: 2px solid #0070E9;
    }

    .typeSelectTextItem {
      padding: 8px 14px;
      background: #F6F6F6;
      margin-top: 20px;
      border-radius: 4px 4px 4px 4px;
      border: 1px solid #999999;
      font-family: Segoe UI, Segoe UI;
      font-weight: 600;
      font-size: 14px;
      color: #333333;
      line-height: 14px;
      text-align: center;
      font-style: normal;
      text-transform: none;
      margin-right: 16px;
      cursor: pointer;
    }

    .typeSelectTextItem_action {
      padding: 8px 14px;
      background: #0070E9;
      margin-top: 20px;
      border-radius: 4px 4px 4px 4px;
      border: 1px solid #999999;
      font-family: Segoe UI, Segoe UI;
      font-weight: 600;
      font-size: 14px;
      color: #333333;
      line-height: 14px;
      text-align: center;
      font-style: normal;
      text-transform: none;
      margin-right: 16px;
      cursor: pointer;
      color: white;
    }
  }

  .noDataText {
    font-family: Segoe UI, Segoe UI;
    font-weight: 600;
    font-size: 16px;
    color: #999999;
    line-height: 16px;
    text-align: left;
    font-style: normal;
    text-transform: none;
    margin-top: 12px;
  }
}

.btnList {
  display: flex;
  justify-content: space-between;
  margin-top: 50px;

  .shiyongBtn {
    width: 219px;
    height: 48px;
    border-radius: 8px 8px 8px 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }

  .iconBtn {
    width: 48px;
    height: 48px;
    background: #FFFFFF;
    border-radius: 8px 8px 8px 8px;
    border: 1px solid #CCCCCC;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;

    img {
      width: 24px;
      height: 24px;
    }
  }

  .buyBtn {
    background: #0070E9;
    color: white;
  }

  .shopping {
    background: #F3F6F8;
  }
}
</style>
